package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.HoDormitoryInfo;
import com.ruoyi.system.service.IHoDormitoryInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 宿舍信息Controller
 *
 * @author ruoyi
 * @date 2025-01-10
 */
@RestController
@RequestMapping("/system/dormitoryInfo")
public class HoDormitoryInfoController extends BaseController {
    @Autowired
    private IHoDormitoryInfoService hoDormitoryInfoService;

    /**
     * 查询宿舍信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:dormitoryInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(HoDormitoryInfo hoDormitoryInfo) {
        startPage();
        List<HoDormitoryInfo> list = hoDormitoryInfoService.selectHoDormitoryInfoList(hoDormitoryInfo);
        return getDataTable(list);
    }

    /**
     * 导出宿舍信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:dormitoryInfo:export')")
    @Log(title = "宿舍信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HoDormitoryInfo hoDormitoryInfo) {
        List<HoDormitoryInfo> list = hoDormitoryInfoService.selectHoDormitoryInfoList(hoDormitoryInfo);
        ExcelUtil<HoDormitoryInfo> util = new ExcelUtil<HoDormitoryInfo>(HoDormitoryInfo.class);
        util.exportExcel(response, list, "宿舍信息数据");
    }

    /**
     * 获取宿舍信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:dormitoryInfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(hoDormitoryInfoService.selectHoDormitoryInfoById(id));
    }

    /**
     * 新增宿舍信息
     */
    @PreAuthorize("@ss.hasPermi('system:dormitoryInfo:add')")
    @Log(title = "宿舍信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HoDormitoryInfo hoDormitoryInfo) {
        hoDormitoryInfo.setCreateUserId(getUserId());
        return toAjax(hoDormitoryInfoService.insertHoDormitoryInfo(hoDormitoryInfo));
    }

    /**
     * 修改宿舍信息
     */
    @PreAuthorize("@ss.hasPermi('system:dormitoryInfo:edit')")
    @Log(title = "宿舍信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HoDormitoryInfo hoDormitoryInfo) {
        hoDormitoryInfo.setUpdateUserId(getUserId());
        return toAjax(hoDormitoryInfoService.updateHoDormitoryInfo(hoDormitoryInfo));
    }

    /**
     * 删除宿舍信息
     */
    @PreAuthorize("@ss.hasPermi('system:dormitoryInfo:remove')")
    @Log(title = "宿舍信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(hoDormitoryInfoService.deleteHoDormitoryInfoByIds(ids));
    }

    /**
     * 查询宿舍信息列表
     */
    @GetMapping("/query")
    public TableDataInfo query(HoDormitoryInfo hoDormitoryInfo) {
        List<HoDormitoryInfo> list = hoDormitoryInfoService.queryHoDormitoryInfoList(hoDormitoryInfo);
        return getDataTable(list);
    }
}
